require(['./config'],() => {
	require(['swiper','template',"request",'header','footer'],(Swiper,template,req,header)=>{
		class List{
			constructor() {
			    this.getListProd()
				this.hover()
			}
			getListProd(){
				const str = window.location.search.split('=')[1]
				this.getListDate(str)
			}
			// 发送请求
			getListDate(prodId){
				req.getListProdData(prodId).then(res => {
					if(res.code === 200){
						console.log(res.data)
						const {categories,items} = res.data
						this.creatTabs(categories)
						this.creatList(items)
						let {nextIndex} = items
						let Height = document.getElementById("selector").offsetHeight
						let height = document.getElementById("footer").offsetHeight
						window.onscroll= function(){
							if(document.documentElement.scrollTop+height >= Height){
								req.getfeedsListProdData(prodId,nextIndex).then(res => {
									if(res.code === 200){
										const {list} = res.data
										nextIndex = res.data.nextIndex
										const html = $('.list-C').html()
										$('.list-C').html(html + template('prodListTemplate',{list}))
									}
								})
							}
						}
					}
				})
			}
			creatTabs(categories){
				// console.log(categories)
				$('.dropdown-list1').html(template('listTabsTemplate',{categories}))
			}
			creatList(prodList){
				const {list} = prodList
				const html = template('prodListTemplate',{list})
				$('.list-C').html(html)
				
			}
			hover(){
				$('#fenlei').click(function(){
					$('.dropdown-list1').slideToggle(500, 'linear', function() {})
				})
				$('#fenlei-list').click(function(){
					$('.dropdown-list2').slideToggle(500, 'linear', function() {})
				})
				
				$('#filter').click(function(){
					$('.category-filter').slideToggle(100, 'linear', function() {})
				})
				
				$('.narrow-by-list>dt').click(function(){
					$(this).attr('aria-expanded','true').next('dd').slideToggle(300, 'linear', function() {})
					$(this).siblings('dt').attr('aria-expanded','false');
				})
				
				$('.btn-default.btn-bing').click(function(){
					$('.product-shop ul.btn-bing').slideToggle(0, 'linear', function() {})
				})
				$('.btn-default.btn-bing').blur(function(){
					$('.product-shop ul.btn-bing').css('display','none')
				})
				
				$('.product-shop ul.btn-bing>li').click(function(){
					$(this).attr('class','bg').siblings().attr('class','')
				})
				
			}
			
		}
		return new List();
	})
})